﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls;
using System.Web.UI;
using Business;
using Application;
using Framework;

namespace PictureControls
{
    public class DisplayPicture : WebControl
    {
        #region Properties

        private VOImage pictureToDisplay;

        public VOImage Picture
        {
            get { return pictureToDisplay; }
            set { pictureToDisplay = value; }
        }

        /// <summary>
        /// La clé de tag à écrire
        /// </summary>
        protected override HtmlTextWriterTag TagKey
        {
            get
            {
                return HtmlTextWriterTag.Div;
            }
        }
        #endregion

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            #region delete button
            ImageButton deleteButt = new ImageButton();
            deleteButt.ImageUrl = "/Images/Test/delete.png";
            #endregion

            #region edit button
            ImageButton editButt = new ImageButton();
            editButt.ImageUrl = "/Images/Test/edit.jpg";
            editButt.OnClientClick = string.Format("javascript:displayUpdatePopup('{0}', '{1}', '{2}'); return false;", Picture.Id, Picture.Title, Picture.Description);
            editButt.CssClass = "buttUpdateImg";
            #endregion

            #region Panel to manage buttons
            Panel pnlEditImg = new Panel();
            pnlEditImg.Controls.Add(deleteButt);
            pnlEditImg.Controls.Add(new LiteralControl("<br>"));
            pnlEditImg.Controls.Add(editButt);
            pnlEditImg.CssClass = "float_left";
            #endregion

            UpdateImageDetails updateImagePanel = (UpdateImageDetails)Page.LoadControl("/UserControls/PictureControls/UpdateImageDetails.ascx");
            updateImagePanel.PictureId = Picture.Id;
            updateImagePanel.ImgUrl = Picture.ImageSource;
            updateImagePanel.ImgDesc = Picture.Description;
            updateImagePanel.ImgTitle = Picture.Title;
            Controls.Add(updateImagePanel);
        }

        protected void editButt_Click(object sender, EventArgs args)
        {
            if (Page.Session[SessionConstants.SessionImageId] != null)
            {
                Page.Session.Contents.Remove(SessionConstants.SessionImageId);
            }
            Page.Session[SessionConstants.SessionImageId] = Picture.Id;
        }
    }

}
